package com.yyplatform.admin.platform.role.controller;

import static com.yyplatform.admin.Constants.URL_PREFIX;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yyplatform.admin.infra.model.RestResponse;
import com.yyplatform.admin.platform.role.model.dto.SysCaptchaLogDTO;
import com.yyplatform.admin.platform.role.model.dto.SysCaptchaLogQueryDTO;
import com.yyplatform.admin.platform.role.service.SysCaptchaLogService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author sleepforests@163.com
 * <p>
 * Created on 2024/9/24 23:08
 */
@Slf4j
@Tag(name = "用户/错误日志管理")
@AllArgsConstructor
@RestController
@RequestMapping(URL_PREFIX + "/sys/captchaLog/")
public class SysCaptchaLogController {

    private SysCaptchaLogService sysCaptchaLogService;


    @GetMapping("query")
    @Operation(summary = "查询")
    @RequiresPermissions("sys:captchaLog:query")
    public RestResponse<Page<SysCaptchaLogDTO>> query(SysCaptchaLogQueryDTO queryDTO) {
        log.debug("query dto = {}", queryDTO);

        Page<SysCaptchaLogDTO> page = sysCaptchaLogService.query(queryDTO);

        return RestResponse.ok(page);
    }

    @PostMapping("delete")
    @Operation(summary = "删除")
    @RequiresPermissions("sys:captchaLog:delete")
    public RestResponse<Void> delete(Long id) {
        log.debug("delete id :{}", id);

        sysCaptchaLogService.delete(id);
        return RestResponse.ok(null);
    }


    @PostMapping("deleteAll")
    @Operation(summary = "批量删除")
    @RequiresPermissions("sys:captchaLog:deleteAll")
    public RestResponse<Void> deleteBatch() {

        sysCaptchaLogService.deleteAll();
        return RestResponse.ok(null);
    }
}
